<?php

namespace App\Models;

use Illuminate\Database\Eloquent\SoftDeletes;

class Image extends ModelBase
{
    use SoftDeletes;

    protected $dates    = ['deleted_at'];

    protected $table    = 'images';

    protected $fillable = [
	    'image_url',
	    'user_id',
	    'target_id',
	    'target_type',
	    'url',
	    'item_id',
	    'status',
    ];
	public function scopeStatus($query){
		return $query->where('status',self::STATUS_NORMAL);
	}
	public function get_item_progress_images($item_id)
	{
		return $this->select('image_url')
			->status()
			->where('target_type', self::TYPE_IMAGE_PROGRESS)
			->where('item_id', $item_id)
			->orderBy('created_at','desc')
			->lists('image_url');
	}

	public function get_progress_images($progress_id)
	{
		return $this->select('image_url')
			->status()
			->where('target_type', self::TYPE_IMAGE_PROGRESS)
			->where('target_id', $progress_id)
			->orderBy('created_at','desc')
			->lists('image_url');
    }

    /**
     * 获取所有的
     */
	public function get_item_cover_images($target_id)
	{
		return $this->select('image_url')
			->status()
			->where('target_type', self::TYPE_IMAGE_COVER)
			->where('target_id', $target_id)
			->orderBy('created_at','desc')
			->lists('image_url');
	}
	/**
	 * 获取项目对应所有进展项目电影截图
	 */
	public function get_item_progress_screenshot_images($item_id)
	{
		return $this->select('image_url')
			->status()
			->where('target_type', self::TYPE_IMAGE_VIDEO_BACKGROUND)
			->where('item_id', $item_id)
			->orderBy('created_at','desc')
			->get()
			->pluck('image_url');
	}

	public function get_item_cover_image($item_id)
	{
		return $this->select(['image_url','url'])
			->status()
			->where('target_type', self::TYPE_IMAGE_COVER)
			->where('target_id', $item_id)
			->orderBy('created_at','desc')
			->first();
	}
	//获取line cover
	public function get_item_line_cover_image($id)
	{
		return $this->select('image_url')
			->status()
			->where('target_type', self::TYPE_IMAGE_LINE_COVER)
			->where('target_id', $id)
			->orderBy('created_at','desc')
			->first();
	}
	//获取line cover 列表
	public function get_item_line_cover_images($id)
	{
		return $this->select('image_url')
			->status()
			->where('target_type', self::TYPE_IMAGE_LINE_COVER)
			->where('target_id', $id)
			->orderBy('created_at','desc');
	}
	public function get_type_by_index_banner_images()
	{
		return $this->select(['image_url','url'])
			->status()
			->where('target_type', self::TYPE_IMAGE_INDEX)
			->orderBy('created_at','desc')
			->get();
	}

	/**
	 * 通过项目ID查询团队成员背景图
	 */
	public function get_member_background_image_by_item($item_id)
	{
		return self::status()
			->where('target_type', '=', self::TYPE_IMAGE_MEMBER_BACKGROUND)
			->where('item_id', '=', $item_id)
			->first();
	}
	/**
	 * all search
	 */
	public function search_images($cond)
	{
		return self::status();
	}
}
